from common.register_data import RegisterData
from page.address_page import AddressPage
from page.login_page import LoginPage, login_url


class AddressScripts(object):
    def __init__(self, driver):
        self.random = RegisterData()
        self.address = AddressPage(driver)
        login = LoginPage(driver)
        login.open_url(login_url)
        login.input_username("yangjun")
        login.input_password("123456")
        login.click_submit()
        self.address.click_user_center()
        self.address.click_shipping_address()

    def input_mandatory(self):
        """输入必填项"""
        self.address.choice_provinces()  # 选择省市区
        name = self.random.get_rand_username()
        self.address.input_name(name)  # 随机输入姓名
        self.address.input_detailed_address("新程大道78号")  # 输入收货地址
        tel = self.random.get_random_tel()
        self.address.input_tel(tel)  # 随机生成电话
        email = self.random.RandomEmail()
        self.address.input_email(email)  # 随机生成邮箱地址
        self.address.click_submit_add()  # 点击新增收货地址


    def input_all_data(self):
        """输入全部数据"""
        self.address.choice_provinces()  # 选择省市区
        name = self.random.get_rand_username()
        self.address.input_name(name)  # 随机输入姓名
        self.address.input_detailed_address("天府大道119号")  # 输入收货地址
        tel = self.random.get_random_phone()
        self.address.input_tel(tel)  # 随机生成电话
        email = self.random.RandomEmail()
        self.address.input_email(email)  # 随机生成邮箱地址
        code = self.random.get_random_phone()
        self.address.input_postal_code(code)  # 随机生成邮编
        mobile = self.random.get_random_tel()
        self.address.input_mobile(mobile)  # 随机生成手机
        self.address.click_submit_add()  # 点击新增收货地址
        self.address.click_delete()  # 点击删除


if __name__ == '__main__':
    asc = AddressScripts()
    # asc.input_mandatory()
    asc.input_all_data()
